LOADING_FLAG = false;
HAVE_APPLYED = false;
TEMPDATA = null;
$(function(){
	initData();
	initUploadSimple({showDelBtn:true});//调用完整方法
});

function initData(){
	$.post('/getSysDictList',{id:8},function(rsp){
		if(rsp){
			frontLoginCheck(rsp);//登陆检查 
			if(rsp.status == 'success'){
				var data = rsp.rows[0];
				//lh.alert('申请开通拍卖专场需要押金'+data.dictValue);
				$("#tip").text('入驻专场需要交纳押金 '+data.dictValue+' 元');
			}else{
				lh.alert(rsp.msg);
			}
		}
	},'json');
}

function doAutoOffer(flag){
	if(flag == 'cancel'){
		$('#offerWin').hide();
	}else if(flag == 'save'){
		var payPass = $("#payPass").val();
		if(!payPass){
			lh.alert('请输入支付密码');
			return;
		}
		TEMPDATA.payPass = payPass;
		LOADING_FLAG = true;//正在加载
		$.post('/addOrUpdateApply',TEMPDATA,function(rsp){
			LOADING_FLAG = false;//取消正在加载
			$('#loadingTip,#offerWin').hide();
			frontLoginCheck(rsp);//登陆检查 
			if(rsp){
				if(rsp.success){
					HAVE_APPLYED = true;
					lh.alert('入驻申请已成功提交，请耐心等待，审核通过后即成功入驻专场');
				}else{
					lh.alert(rsp.msg);return;
				}
				setTimeout(function(){
					var url = '/auctionInst';
					var r = $("#r").val();
					if(r) url += "?r="+r;
					window.location.href = url;
				},4000);
			}
		},'json');
	}
}

function submitInstApply(){
	if(LOADING_FLAG)return;
	if(HAVE_APPLYED){
		lh.alert('您已成功提交申请，请耐心等待审核');return;
	}
	var instName = $('#instName').val();
	if(!instName){
		lh.alert('请输入专场名称');return;
	}
	var filePaths = $("#filePaths").val();
	if(!filePaths){frontBaseConfirm('如果不上传机构图标,那么您的头像将做为机构图标','showPassWin()','');}
	var filePathArr = new Array();
	if(filePaths.indexOf(',') >= 0){
		filePaths = filePaths.substring(1);
	}
	filePathArr = filePaths.split(",");
	if(filePathArr.length >= 2){
		lh.alert('只能上传1张本场图片');
		SAVING_FLAG = false;
		return;
	}
	var tel = $("#tel").val();
	if(!tel){
		lh.alert('请输入联系电话');return;
	}
	$('#resultTip').hide();
	$('#loadingTip').show();
	var param = {attr1:instName,applyType:92,attr2:tel};
	if(filePaths){
		param.file1 = filePaths;
	}
	var message = $('#message').val();
	param.message = message;
	TEMPDATA = param;
	if(filePaths){
		$('#offerWin').show();
	}
}

function showPassWin(){
	$('#offerWin').show();
}



